package org.dromara.job.processors;

import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.dromara.patrol.api.RemotePatrolSubtaskCommonService;
import org.springframework.stereotype.Component;
import tech.powerjob.worker.core.processor.ProcessResult;
import tech.powerjob.worker.core.processor.TaskContext;
import tech.powerjob.worker.core.processor.sdk.BasicProcessor;

/**
 * 巡店管理-巡店子主任务状态刷新处理器
 */
@Slf4j
@Component
public class PatrolTaskCheckMainExpiredProcessor implements BasicProcessor {
    @DubboReference(timeout = 10000)
    private RemotePatrolSubtaskCommonService remotePatrolSubtaskCommonService;
    @Override
    public ProcessResult process(TaskContext taskContext) throws Exception {
        // 刷新已建任务状态
        Long id = Long.valueOf(taskContext.getJobParams());
        log.info("开始执行状态刷新任务，任务ID:{}", id);
        Boolean ret = remotePatrolSubtaskCommonService.updateMainPatrolTask(id);
        log.info("结束执行状态刷新任务，任务ID:{}", id);
        if (ret == null || !ret) {
            return new ProcessResult(false, "任务状态更新失败");
        }
        return new ProcessResult(true, "任务成功啦！！！");
    }
}
